import Vue from 'vue'
import { HttpResetClass } from 'vue-client'

let CardListen = {
    // 开启卡监听
  startListen () {
    // this.hasCard = true
    let http = new HttpResetClass()
    let that = this
    setInterval(() => {
      http.load('POST', 'http://127.0.0.1:8003/HasCard', {}, {resolveMsg: null, rejectMsg: null}).then((res) => {
        let state = JSON.parse(res.data).state
        if (state === 0) {
          that.cardState = -1
          // 关闭监听
          // clearInterval(interval)
        } else if (state === 1 && that.cardState !== 1) {
          that.cardState = 0
        }
      }).catch((error) => {
      })
    }, 1000)
  }
}

// HttpStore是否正在工作 -1：无卡 0：有卡 1：可操作
Vue.set(CardListen, 'cardState', -1)

export default CardListen
